﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DDL_Category.ascx.cs" Inherits="BBPA.Admin.Controls.DDL_Category" %>
<table>
    <tr>
        <td width="33%">
            <%--<asp:ListBox ID="ddl1" runat="server" data-categorylev="1" Rows="5" onchange="DDL_Category_changed(this)" EnableViewState="False"></asp:ListBox>--%>
            <select ID="ddl1" style="width:100%" runat="server" size="5" data-categorylev="1"  onchange="DDL_Category_changed(this)" data-noselect2="1"></select>
        </td>
        <td width="33%">
            <%--<asp:ListBox ID="ddl2" runat="server" data-categorylev="2" Rows="5" onchange="DDL_Category_changed(this)" EnableViewState="False"></asp:ListBox>--%>
            <select ID="ddl2" style="width:100%" runat="server" size="5" data-categorylev="2" onchange="DDL_Category_changed(this)" data-noselect2="1"></select>

        </td>
        <td width="33%">
            <%--<asp:ListBox ID="ddl3" runat="server" data-categorylev="3" Rows="5" onchange="DDL_Category_SetVal(this)" EnableViewState="False"></asp:ListBox>--%>
            <select ID="ddl3" style="width:100%" runat="server" size="5" data-categorylev="3"  onchange="DDL_Category_SetVal($(this))" data-noselect2="1"></select>
            <asp:TextBox ID="tb_Category" runat="server" CssClass="hide"></asp:TextBox>
        </td>
    </tr>
</table>

<script>
    function DDL_Category_changed(w_) {
        var w = $(w_);
        $.ajax({
            type: "post", dataType: "jsonp",
            url: "http://api.aiyoubb.com/category.ashx",
            data: { FatherCategoryID: w.val() },
            success: function (callBak) {
                if (callBak.IsSuccess) DDL_Category_changed_ok(w, callBak.ReturnVal);
                else if (callBak.ErrorString != "") alert(callBak.ErrorString);
            }
        });
    }
    function DDL_Category_changed_ok(w, ListCategory_) {
        var thisCategoryLev = w.attr("data-categorylev");
        var sonSelect = w.parents("tr").find("select[data-categorylev=" + accAdd(thisCategoryLev, 1) + "]");
        sonSelect.find("option").remove();
        for (var i = 0; i < ListCategory_.length; i++) sonSelect.append("<option value=\"" + ListCategory_[i].id + "\">" + ListCategory_[i].Name + "</option>");
        sonSelect.val(ListCategory_[0].id);
        if (thisCategoryLev * 1 == 1) DDL_Category_changed(sonSelect);
        else DDL_Category_SetVal(sonSelect);
    }
    function DDL_Category_SetVal(w) {
        w.siblings("input").val(w.val());
    }
</script>
